package ATMproject;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu extends JPanel implements ActionListener {
    //声明交互按钮
    private JButton backBtn;

    private MainPage frame;

    private JButton saveBtn;
    private JButton drawBtn;
    private JButton inquireBtn;
    private JButton transformBtn;
    private JButton changeBtn;

    private Icon backButton = Util.getIcon("/atmimage/buttonOff.jpg");
    private Icon saveButton = Util.getIcon("/atmimage/buttonSave.jpg");
    private Icon drawButton = Util.getIcon("/atmimage/buttonGet.jpg");
    private Icon inquireButton = Util.getIcon("/atmimage/buttonFind.jpg");
    private Icon transformButton = Util.getIcon("/atmimage/pane.jpg");
    private Icon changeButton = Util.getIcon("/atmimage/buttonModify.jpg");

    public Menu(MainPage frame) {
        this.frame = frame;

        this.setLayout(null);

        this.setOpaque(false);

//        JLabel titleLabel = new JLabel("菜单");
//        titleLabel.setBounds(200, 50, 100, 50);
//        this.add(titleLabel);

        backBtn = new JButton(backButton);
        backBtn.setBounds(650, 200, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

        saveBtn = new JButton(saveButton);
        saveBtn.setBounds(650, 20, 100, 50);
        this.add(saveBtn);
        saveBtn.addActionListener(this);

        drawBtn = new JButton(drawButton);
        drawBtn.setBounds(650, 80, 100, 50);
        this.add(drawBtn);
        drawBtn.addActionListener(this);

        inquireBtn = new JButton(inquireButton);
        inquireBtn.setBounds(650, 140, 100, 50);
        this.add(inquireBtn);
        inquireBtn.addActionListener(this);

        transformBtn = new JButton("转账");
        transformBtn.setBounds(0, 140, 100, 50);
        this.add(transformBtn);
        transformBtn.addActionListener(this);

        changeBtn = new JButton(changeButton);
        changeBtn.setBounds(0, 240, 100, 50);
        this.add(changeBtn);
        changeBtn.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (backBtn == e.getSource()) {
            frame.switchPanel("login");
        }
        if (saveBtn == e.getSource()) {
            frame.switchPanel("save");
        }
        if (drawBtn == e.getSource()) {
            frame.switchPanel("draw");
        }
        if (inquireBtn == e.getSource()) {
            frame.getInquire().getInquireText().setText(frame.getUserarraylist().get(frame.getIndex()).getMoney() + "");
            frame.switchPanel("inquire");
        }
        if (transformBtn == e.getSource()) {
            frame.switchPanel("transform");
        }
        if (changeBtn == e.getSource()) {
            frame.switchPanel("change");
        }

    }
}
